package com.zyp.test.test;

import android.content.res.Resources;
import android.util.DisplayMetrics;

/**
 * @author zyp
 *         2017/12/25
 */

public class DisplayUtil {
   
    static {
        DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
        density = displayMetrics.density;
        scaledDensity = displayMetrics.scaledDensity;
    }
    private static float density;
    private static float scaledDensity;

    public static int px2dip(float px){
        return (int) (px/density + 0.5f);
    }
    
    public static float dip2px(float dp){
        return dp*density;
    }
    public static int px2sp(float px){
        return (int) (px/scaledDensity + 0.5f);
    }
    public static float sp2px(float sp){
        return  sp*scaledDensity;
    }
}
